package com.hankol.material

import com.alibaba.android.arouter.facade.annotation.Route
import com.baselibrary.activity.BaseActivity
import com.baselibrary.router.ActivityRouter
import com.hankol.material.api.MaterialConstants
import com.hankol.material.bean.FolderListBean
import com.hankol.material.bean.MaterialBusinessBean
import com.hankol.material.databinding.ActivityCollectionFolderBinding
import com.hankol.material.fragment.MaterialControlContentFragment
import com.hankol.material.viewmodel.CollectionFolderViewModel

@Route(path = ActivityRouter.MATERIAL.MATERIAL_COLLECTION_FOLDER)
class CollectionFolderActivity : BaseActivity() {
    private lateinit var mViewModel: CollectionFolderViewModel
    private lateinit var dataBinding: ActivityCollectionFolderBinding
    private var mFolderBean: FolderListBean? = null
    override fun getLayoutId(): Int {
        return R.layout.activity_collection_folder
    }

    override fun init() {
        mViewModel = getActivityViewModelProvider(this).get(CollectionFolderViewModel::class.java)
        dataBinding = getDataBinding<ActivityCollectionFolderBinding>()



        intent.extras?.let {
            if (it.containsKey(MaterialConstants.FOLDER_DETAIL)) {
                mFolderBean = it.getSerializable(MaterialConstants.FOLDER_DETAIL) as FolderListBean
            }
        }

        dataBinding.llCollectionFolderBack.setOnClickListener { finish() }

        mFolderBean?.let {
            dataBinding.tvCollectionFolderTitle.text = it.name
            val fragment = MaterialControlContentFragment.newInstance(MaterialBusinessBean(MaterialConstants.BUSINESS_TYPE_FOLDER, "", 0, it.id, 1), null, true,this)
            supportFragmentManager.beginTransaction().add(R.id.fragment_collectionFolder, fragment).commitAllowingStateLoss()
        }

    }
}
